// pages/auth/accountLogin/accountLogin.js
const util=require('../../../utils/util')
const api =require('../../../config/api')
var app =getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    account:'123456',
    password:'123123'
  },
  loginText(e){
    this.setData({
      account:e.detail.value
    })
    console.log(this.data.account);
  },
  passwordText(e){
    this.setData({
      password:e.detail.value
    })
    console.log(this.data.password);
  },
// 账号登录按钮
  loginIn:function(){
    let that =this
    util.request(api.AuthLoginByAccount,{
      username:that.data.account,
      password:that.data.password,
    },'post').then(res=>{
      console.log(res);
      if(res.errno==700){
        wx.showToast({
          title: '账号密码不对',
          duration: 2000,
          icon:'none'
          });
      }
      if(res.errno==0){
        app.globalData.hasLogin=true
        wx.setStorageSync('userInfo', res.data.userInfo)
        wx.setStorage({
          key:'token',
          data:res.data.token,
          success:function(){
            wx.navigateBack({
              delta:2
            })
            // wx.switchTab({
            //   url: '/pages/ucenter/index/index',
            // })
          }
        })
      }
    })
  }


})